import os
import shutil
import sys
# 需要遍历的目录

def clean_pycache(root_dir):
    for dirpath, dirnames, filenames in os.walk(root_dir):
        if "__pycache__" in dirnames:
            # 获取 __pycache__ 目录的全路径
            pycache_dir = os.path.join(dirpath, "__pycache__")
            # 删除目录
            shutil.rmtree(pycache_dir)
            print(f"Removed: {pycache_dir}")

if __name__ == '__main__':
    root_dir = sys.argv[1]
    clean_pycache(root_dir)
